<?php

class AuthAction extends BaseAction
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 登录
     */
    public function index()
    {
        C('LAYOUT_ON',false);
        $this->display();
    }

    /**
     * 执行登录
     */
    public function login()
    {
        $username = I('post.username');
        $password = I('post.password');
        $item = array('status'=>0,'msg'=>'');


        $map['username']	=  $username;
        $map['password']	=  md5($password);
        $map['type']	    =  1;
        $map['_logic']      =   'AND';

        $rs = M('User')->where($map)->find();
        if ($rs) {
            session('site', $rs);
            echo json_encode($item);exit;
        }
        $item['status'] = 1;
        $item['msg'] = '用户名或密码错误';
        echo json_encode($item);exit;
    }


    /**
     * 登出
     */
    public function loginOut()
    {
        Session('site', null);
        header("Location:" .__ROOT__. "/index.php/Medium/Auth/index");
    }

}


?>